#include "GrooveHeader.h"

void main()
{
	int k;
	int seq[2] = {3};
	int fullSeq[NUMSYMB];
	int i,j,p;
	char *fileList[] = {"01.txt","02.txt","03.txt","04.txt"};
	char *pstr = "../../GrooversSVN/GrooveTemplates/Groove";
	char fstr[MAX_PATH_LENGTH];
	FILE *fp;
	int GrooveLabel;
	Groove groove1;
	Groove gTemplates[NUM_GROOVES];
	Groove *gTlptr;
	Groove *gptr;
	int temp1, temp2;
	int Label[NUMSYMB];
	int tp;
	// Tree variables
	srch srchparams;
	prob var;
	pstNode PST, PSTinit, node, node1;
	pstData data;
	// Predictive distribution
	float probab[NUM_GROOVES];
	// Code starts
	k=0;
	for(j = 0;j<NUM_GROOVE_TEMPLATES;j++){
		strcpy(fstr,pstr);
		fp = fopen(strcat(fstr,fileList[j]),"rt");
		puts(fstr);
		if(!fp)
			printf("File Not Found");
		else{
			while(!feof(fp)){
				fscanf(fp,"%d %d\n", &temp1, &temp2);
				gTemplates[j].note[k] = (char)(getNoteName(temp1));
				gTemplates[j].dur[k] = (char)(getDurName(temp2));
				k++;
			}
			gTemplates[j].length = k;
			gTemplates[j].note[k] = '\0';
			gTemplates[j].dur[k] = '\0';
			k = 0;
		}
		fclose(fp);
	}
	gTlptr = (Groove*)(&gTemplates[0]);
	PST = createTree();
	tp = 0;
	for(k = 0;k<NUMSYMB;k++){
		tp = (int)((float)(rand())/(float)(RAND_MAX)*(float)(NUM_GROOVE_TEMPLATES));
		//if(tp > 3)
		//	tp = 0;
		printf("Input Groove number = %d\n",tp+1);
		gptr = (Groove*)(&gTemplates[tp]);
		Label[k] = GrooveClassify(gptr, gTlptr,NUM_GROOVE_TEMPLATES);
		printf("Test Assigned Label = %d\n",Label[k]);
		//PST = growPST(PST, Label, NUMSYMB, DMAX);	
		PST = buildPSTRealTime(PST, Label, findmax(0,k-DMAX), k);
		getPredSymbDist(PST, Label, findmax(0,k-DMAX), k, NUM_GROOVE_TEMPLATES, probab);
		printf("Symbols so far: ");
		for(i=0;i<=k;i++){
			printf("%d ",Label[i]);
		}
		printf("\nPredictive Distribution :\n");
		for(i=0;i<NUM_GROOVE_TEMPLATES;i++){
			printf("%d:%.2f\n",i+1,probab[i]);
		}
	}
	//var = getCondProbBackoff(PST, Label, 5, 5, DMAX);
	getch();
}
